<template>
  <div class="app-container">
    <el-form class="top" :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="游客id" prop="touristId">
        <el-input
          v-model="queryParams.touristId"
          placeholder="请输入游客id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结果1" prop="recommend1">
        <el-input
          v-model="queryParams.recommend1"
          placeholder="请输入结果1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结果2" prop="recommend2">
        <el-input
          v-model="queryParams.recommend2"
          placeholder="请输入结果2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结果3" prop="recommend3">
        <el-input
          v-model="queryParams.recommend3"
          placeholder="请输入结果3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结果4" prop="recommend4">
        <el-input
          v-model="queryParams.recommend4"
          placeholder="请输入结果4"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结果5" prop="recommend5">
        <el-input
          v-model="queryParams.recommend5"
          placeholder="请输入结果5"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结果6" prop="recommend6">
        <el-input
          v-model="queryParams.recommend6"
          placeholder="请输入结果6"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['task:recommend:add']"
        >新增</el-button>
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['task:recommend:edit']"-->
<!--        >修改</el-button>-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['task:recommend:remove']"-->
<!--        >删除</el-button>-->
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['task:recommend:export']"
        >导出</el-button>
      </el-form-item>
    </el-form>
    <el-col :span="6" class="card-box" v-for="item in this.recommendList">
        <el-card class="card-front":style="{backgroundImage:'url(https://www.universalbeijingresort.com/sites/default/files/2021-09/Jurasssic%20Flyer_1.jpg)'}">
          <div class="card-header">
            <div class="card-name">
              <span>游客{{item.touristId}}</span>
              <div class="card-title">1：{{item.recommend1}}</div>
              <div class="card-title">2：{{item.recommend2}}</div>
              <div class="card-title">3：{{item.recommend3}}</div>
              <div class="card-title">4：{{item.recommend4}}</div>
              <div class="card-title">5：{{item.recommend5}}</div>
              <div class="card-title">6：{{item.recommend6}}</div>
            </div>
          </div>
          <div class="card-bottom">
            <el-button
              class="card-button-edit"
              size="mini"
              @click="handleUpdate(item)"
              v-hasPermi="['recommend:data:edit']"
            >修改</el-button>
            <el-button
              class="card-button-delete"
              size="mini"
              @click="handleDelete(item)"
              v-hasPermi="['recommend:data:remove']"
            >删除</el-button>
          </div>
        </el-card>
    </el-col>
    <!--    为了让分页的那个条下去，不要错位-->
    <div style="clear: both;"></div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改推荐结果管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="游客id" prop="touristId">
          <el-input v-model="form.touristId" placeholder="请输入游客id" />
        </el-form-item>
        <el-form-item label="推荐结果1" prop="recommend1">
          <el-input v-model="form.recommend1" placeholder="请输入推荐结果1" />
        </el-form-item>
        <el-form-item label="推荐结果2" prop="recommend2">
          <el-input v-model="form.recommend2" placeholder="请输入推荐结果2" />
        </el-form-item>
        <el-form-item label="推荐结果3" prop="recommend3">
          <el-input v-model="form.recommend3" placeholder="请输入推荐结果3" />
        </el-form-item>
        <el-form-item label="推荐结果4" prop="recommend4">
          <el-input v-model="form.recommend4" placeholder="请输入推荐结果4" />
        </el-form-item>
        <el-form-item label="推荐结果5" prop="recommend5">
          <el-input v-model="form.recommend5" placeholder="请输入推荐结果5" />
        </el-form-item>
        <el-form-item label="推荐结果6" prop="recommend6">
          <el-input v-model="form.recommend6" placeholder="请输入推荐结果6" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRecommend, getRecommend, delRecommend, addRecommend, updateRecommend } from "@/api/task/recommend";

export default {
  name: "Recommend",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 推荐结果管理表格数据
      recommendList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        touristId: null,
        recommend1: null,
        recommend2: null,
        recommend3: null,
        recommend4: null,
        recommend5: null,
        recommend6: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询推荐结果管理列表 */
    getList() {
      this.loading = true;
      listRecommend(this.queryParams).then(response => {
        this.recommendList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recommendId: null,
        touristId: null,
        recommend1: null,
        recommend2: null,
        recommend3: null,
        recommend4: null,
        recommend5: null,
        recommend6: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recommendId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加推荐结果管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recommendId = row.recommendId || this.ids
      getRecommend(recommendId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改推荐结果管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recommendId != null) {
            updateRecommend(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecommend(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recommendIds = row.recommendId || this.ids;
      this.$modal.confirm('是否确认删除推荐结果管理编号为"' + recommendIds + '"的数据项？').then(function() {
        return delRecommend(recommendIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('task/recommend/export', {
        ...this.queryParams
      }, `recommend_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
